<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
/*
 *  简历
 */
class Resume extends Model
{
    /*
     *  数据表
     */
    protected $table = 'resume`';
    protected  $primaryKey='industry_id';
    /*
     *  简历列表
     *  @ $id 用户id
     */
    static function lists($id){
        $res = DB::select("select `industry_id`,`r_name`,`time`,`default` from resume where status=0 and user_id=$id");
        $i = 1;
        foreach ($res as &$v){
            $v->time = date('Y-m-d H:i:s',$v->time);
            $v->r_name = "简历".$i;
            $i++;
            $v = (array)$v;
        }
        return $res;
    }

    /*
     *  将用户id 入库 生成一条新的简历
     *  但是状态为不可用
     *  $ id   用户id
     */
    static function add($id){
        // 添加并返回 新增id
        $id=DB::table("resume")->insertGetId(['user_id'=>$id]);
        return $id;
    }

    /*
     *  查出用户一些进本信息
     *  @id  用户id
     */
    static function look_user($id){
        $res = DB::select("select `id`,`phone`,`study`,`major`,`education`,`graduation_date`,`mail`,`u_name` from usera where id=$id");
        return $res;
    }


    /*
     *  简历详情
     *   @id  简历id
     */
    static function detail($id){
        $res = DB::select("select * from resume inner join usera on resume.user_id=usera.id join industry on resume.industry=industry.industry_id where resume.industry_id=$id");
        return $res;
    }
    public function  resumeList($id){
        return DB::select("select * from record r INNER JOIN resume e ON r.resume_id=e.industry_id INNER JOIN usera u ON r.uid=u.id INNER JOIN position p ON r.position_id=p.position_id WHERE r.company_id=$id");
    }
    /**
     * 按照职位名称搜索
     */
    public function searchOff($offname){
        return $this->get()->where('off_name','like', '%'.$offname.'%')->toArray();
    }
    /**
     * 按照学历搜索
     */
    public function searchStudy($study)
    {
        return $this->get()->where('education','like', '%'.$study.'%')->toArray();
    }

        /**
         * 按照学校进行查询，简历表联查usera表
         */
        public function searchSchool($school){
            return DB::select("select * from resume as r INNER JOIN usera as u ON r.user_id=u.id WHERE like  u.study='."%$school%".'");
        }
        /**
         * 按照专业查询
         */
        public function searchMajor($major){
            return DB::select("select * from resume as r INNER JOIN usera as u ON r.user_id=u.id where u.major='."%$major%".'");
        }

    /**
     * @param $offname
     * @param $school
     * 按照学校和职位搜索
     */
        public function seachOffSch($offname,$study){
            return $this->get()->where('off_name','like', '%'.$offname.'%')->orWhere('education', 'like', '%'.$study.'%')->toArray();
        }
}
